{% extends "base.html" %}

{% block content %}
<div class="row">
    <div class="col-md-12 mb-4">
        <h2>创建新文章</h2>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">编辑文章内容</h5>
            </div>
            <div class="card-body">
                <form action="" method="post" novalidate>
                    {{ form.hidden_tag() }}
                    <div class="mb-3">
                        {{ form.title.label(class="form-label") }}
                        {{ form.title(class="form-control") }}
                        {% for error in form.title.errors %}
                        <div class="text-danger">{{ error }}</div>
                        {% endfor %}
                    </div>
                    
                    <div class="mb-3">
                        {{ form.skills.label(class="form-label") }}
                        <select class="form-select" id="skills" name="skills" multiple>
                            {% for skill_id, skill_name in form.skills.choices %}
                            <option value="{{ skill_id }}">{{ skill_name }}</option>
                            {% endfor %}
                        </select>
                        <div class="form-text">按住Ctrl键（Mac上为Command键）可以选择多个技能标签</div>
                        {% for error in form.skills.errors %}
                        <div class="text-danger">{{ error }}</div>
                        {% endfor %}
                    </div>
                    
                    <div class="mb-3">
                        {{ form.content.label(class="form-label") }}
                        {{ form.content(class="form-control", rows=15, id="editor") }}
                        {% for error in form.content.errors %}
                        <div class="text-danger">{{ error }}</div>
                        {% endfor %}
                    </div>
                    
                    <div class="d-flex justify-content-between">
                        <a href="{{ url_for('articles.index') }}" class="btn btn-outline-secondary">取消</a>
                        {{ form.submit(class="btn btn-primary") }}
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
    tinymce.init({
        selector: '#editor',
        plugins: 'advlist autolink lists link image charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime media table paste code help wordcount',
        toolbar: 'undo redo | formatselect | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | help',
        height: 500,
        menubar: true
    });
</script>
{% endblock %}